/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * FlightGearOptions.java
 *
 * Created on 21.11.2011, 16:26:22
 */
package com.transas.zorlog.ui;

import java.util.List;
import javax.swing.JComboBox;

/**
 *
 * @author amalikov
 */
@SuppressWarnings("unchecked")
public class FlightGearOptions extends javax.swing.JPanel {

	/** Creates new form FlightGearOptions */
	public FlightGearOptions(List<String> valueNames) {
		initComponents();
		initComboboxes(valueNames);
	}

	public void readValues(AppConfig appConfig) {
		selfAddr.setText(appConfig.getOption(gr, "self"));
		dstAddr.setText(appConfig.getOption(gr, "dst"));
		dstPort.setText(appConfig.getOption(gr, "dstport"));
		latitude.setSelectedItem(appConfig.getOption(gr, "latitude"));
		longitude.setSelectedItem(appConfig.getOption(gr, "longitude"));
		altitude.setSelectedItem(appConfig.getOption(gr, "altitude"));
		airspeed.setSelectedItem(appConfig.getOption(gr, "airspeed"));
		roll.setSelectedItem(appConfig.getOption(gr, "roll"));
		pitch.setSelectedItem(appConfig.getOption(gr, "pitch"));
		heading.setSelectedItem(appConfig.getOption(gr, "heading"));
		aileron.setSelectedItem(appConfig.getOption(gr, "aileron"));
		elevator.setSelectedItem(appConfig.getOption(gr, "elevator"));
		rudder.setSelectedItem(appConfig.getOption(gr, "rudder"));
		throttle.setSelectedItem(appConfig.getOption(gr, "throttle"));
		flaps.setSelectedItem(appConfig.getOption(gr, "flaps"));
		rpm.setSelectedItem(appConfig.getOption(gr, "rpm"));
		offsetEnable.setSelected("1".equals(appConfig.getOption(gr, "offsetenable")));
		offset.setText(appConfig.getOption(gr, "offset"));
		filterEnable.setSelected("1".equals(appConfig.getOption(gr, "filterenable")));
		filterAlpha.setText(appConfig.getOption(gr, "filteralpha"));
		baroalt.setSelectedItem(appConfig.getOption(gr, "baroalt"));
		vspeed.setSelectedItem(appConfig.getOption(gr, "vspeed"));
		gspeed.setSelectedItem(appConfig.getOption(gr, "gspeed"));
		aoa.setSelectedItem(appConfig.getOption(gr, "aoa"));
		slip.setSelectedItem(appConfig.getOption(gr, "slip"));
	}

	public void writeValues(AppConfig appConfig) {
		appConfig.setOption(gr, "self", selfAddr.getText());
		appConfig.setOption(gr, "dst", dstAddr.getText());
		appConfig.setOption(gr, "dstport", dstPort.getText());
		appConfig.setOption(gr, "latitude", latitude.getSelectedItem().toString());
		appConfig.setOption(gr, "longitude", longitude.getSelectedItem().toString());
		appConfig.setOption(gr, "altitude", altitude.getSelectedItem().toString());
		appConfig.setOption(gr, "airspeed", airspeed.getSelectedItem().toString());
		appConfig.setOption(gr, "roll", roll.getSelectedItem().toString());
		appConfig.setOption(gr, "pitch", pitch.getSelectedItem().toString());
		appConfig.setOption(gr, "heading", heading.getSelectedItem().toString());
		appConfig.setOption(gr, "aileron", aileron.getSelectedItem().toString());
		appConfig.setOption(gr, "elevator", elevator.getSelectedItem().toString());
		appConfig.setOption(gr, "rudder", rudder.getSelectedItem().toString());
		appConfig.setOption(gr, "throttle", throttle.getSelectedItem().toString());
		appConfig.setOption(gr, "flaps", flaps.getSelectedItem().toString());
		appConfig.setOption(gr, "rpm", rpm.getSelectedItem().toString());
		appConfig.setOption(gr, "offsetenable", offsetEnable.isSelected() ? "1" : "0");
		appConfig.setOption(gr, "offset", offset.getText());
		appConfig.setOption(gr, "filterenable", filterEnable.isSelected() ? "1" : "0");
		appConfig.setOption(gr, "filteralpha", filterAlpha.getText());
		appConfig.setOption(gr, "baroalt", baroalt.getSelectedItem().toString());
		appConfig.setOption(gr, "vspeed", vspeed.getSelectedItem().toString());
		appConfig.setOption(gr, "gspeed", gspeed.getSelectedItem().toString());
		appConfig.setOption(gr, "aoa", aoa.getSelectedItem().toString());
		appConfig.setOption(gr, "slip", slip.getSelectedItem().toString());
	}
	
	private void initComboboxes(List<String> valueNames) {
		final JComboBox[] comboBoxes = new JComboBox[]{
			latitude, longitude, altitude, airspeed, roll, pitch, heading, 
			aileron, elevator, rudder, throttle, flaps, rpm, baroalt, vspeed, gspeed, aoa, slip};
		for (JComboBox comboBox : comboBoxes) {
			comboBox.removeAllItems();
			for (String valueName : valueNames)
				comboBox.addItem(valueName);
		}
	}
	
	/** This method is called from within the constructor to
	 * initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is
	 * always regenerated by the Form Editor.
	 */
	@SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        selfAddr = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        dstAddr = new javax.swing.JTextField();
        dstPort = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        latitude = new javax.swing.JComboBox();
        jLabel5 = new javax.swing.JLabel();
        longitude = new javax.swing.JComboBox();
        jLabel6 = new javax.swing.JLabel();
        altitude = new javax.swing.JComboBox();
        jLabel7 = new javax.swing.JLabel();
        airspeed = new javax.swing.JComboBox();
        jLabel8 = new javax.swing.JLabel();
        roll = new javax.swing.JComboBox();
        jLabel9 = new javax.swing.JLabel();
        pitch = new javax.swing.JComboBox();
        jLabel10 = new javax.swing.JLabel();
        heading = new javax.swing.JComboBox();
        jLabel11 = new javax.swing.JLabel();
        aileron = new javax.swing.JComboBox();
        jLabel12 = new javax.swing.JLabel();
        elevator = new javax.swing.JComboBox();
        jLabel13 = new javax.swing.JLabel();
        rudder = new javax.swing.JComboBox();
        jLabel14 = new javax.swing.JLabel();
        throttle = new javax.swing.JComboBox();
        jLabel15 = new javax.swing.JLabel();
        flaps = new javax.swing.JComboBox();
        jLabel16 = new javax.swing.JLabel();
        rpm = new javax.swing.JComboBox();
        filterEnable = new javax.swing.JCheckBox();
        filterAlpha = new javax.swing.JTextField();
        offsetEnable = new javax.swing.JCheckBox();
        offset = new javax.swing.JTextField();
        jLabel17 = new javax.swing.JLabel();
        baroalt = new javax.swing.JComboBox();
        jLabel18 = new javax.swing.JLabel();
        vspeed = new javax.swing.JComboBox();
        jLabel19 = new javax.swing.JLabel();
        gspeed = new javax.swing.JComboBox();
        jLabel20 = new javax.swing.JLabel();
        aoa = new javax.swing.JComboBox();
        jLabel21 = new javax.swing.JLabel();
        slip = new javax.swing.JComboBox();

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Connection"));

        jLabel1.setText("Self Addr:");

        jLabel2.setText("Dst Addr:");

        jLabel3.setText("Dst Port:");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2))
                .addGap(29, 29, 29)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(selfAddr)
                    .addComponent(dstAddr, javax.swing.GroupLayout.DEFAULT_SIZE, 136, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 76, Short.MAX_VALUE)
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(dstPort, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(selfAddr, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(dstAddr, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(dstPort, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Values"));
        jPanel2.setLayout(null);

        jLabel4.setText("Latitude:");
        jPanel2.add(jLabel4);
        jLabel4.setBounds(16, 24, 90, 14);

        jPanel2.add(latitude);
        latitude.setBounds(114, 20, 114, 20);

        jLabel5.setText("Longitude:");
        jPanel2.add(jLabel5);
        jLabel5.setBounds(16, 52, 90, 14);

        jPanel2.add(longitude);
        longitude.setBounds(114, 48, 114, 20);

        jLabel6.setText("Altitude:");
        jPanel2.add(jLabel6);
        jLabel6.setBounds(16, 80, 90, 14);

        jPanel2.add(altitude);
        altitude.setBounds(114, 76, 114, 20);

        jLabel7.setText("Airspeed:");
        jPanel2.add(jLabel7);
        jLabel7.setBounds(16, 106, 90, 14);

        jPanel2.add(airspeed);
        airspeed.setBounds(114, 102, 114, 20);

        jLabel8.setText("Roll:");
        jPanel2.add(jLabel8);
        jLabel8.setBounds(16, 134, 90, 14);

        jPanel2.add(roll);
        roll.setBounds(114, 130, 114, 20);

        jLabel9.setText("Pitch:");
        jPanel2.add(jLabel9);
        jLabel9.setBounds(16, 162, 90, 14);

        jPanel2.add(pitch);
        pitch.setBounds(114, 158, 114, 20);

        jLabel10.setText("Heading:");
        jPanel2.add(jLabel10);
        jLabel10.setBounds(16, 190, 90, 14);

        jPanel2.add(heading);
        heading.setBounds(114, 186, 114, 20);

        jLabel11.setText("Ailerons:");
        jPanel2.add(jLabel11);
        jLabel11.setBounds(16, 218, 90, 14);

        jPanel2.add(aileron);
        aileron.setBounds(114, 214, 114, 20);

        jLabel12.setText("Elevator:");
        jPanel2.add(jLabel12);
        jLabel12.setBounds(16, 246, 90, 14);

        jPanel2.add(elevator);
        elevator.setBounds(114, 242, 114, 20);

        jLabel13.setText("Rudder:");
        jPanel2.add(jLabel13);
        jLabel13.setBounds(16, 274, 90, 14);

        jPanel2.add(rudder);
        rudder.setBounds(114, 270, 114, 20);

        jLabel14.setText("Throttle:");
        jPanel2.add(jLabel14);
        jLabel14.setBounds(16, 302, 90, 14);

        jPanel2.add(throttle);
        throttle.setBounds(114, 298, 114, 20);

        jLabel15.setText("Flaps:");
        jPanel2.add(jLabel15);
        jLabel15.setBounds(16, 330, 90, 14);

        jPanel2.add(flaps);
        flaps.setBounds(114, 326, 114, 20);

        jLabel16.setText("RPM:");
        jPanel2.add(jLabel16);
        jLabel16.setBounds(16, 358, 90, 14);

        jPanel2.add(rpm);
        rpm.setBounds(114, 354, 114, 20);

        filterEnable.setText("Filter:");
        jPanel2.add(filterEnable);
        filterEnable.setBounds(262, 48, 91, 20);
        jPanel2.add(filterAlpha);
        filterAlpha.setBounds(359, 48, 61, 20);

        offsetEnable.setText("Offset:");
        jPanel2.add(offsetEnable);
        offsetEnable.setBounds(262, 76, 91, 20);
        jPanel2.add(offset);
        offset.setBounds(359, 74, 61, 20);

        jLabel17.setText("BaroAlt:");
        jPanel2.add(jLabel17);
        jLabel17.setBounds(250, 130, 50, 14);

        jPanel2.add(baroalt);
        baroalt.setBounds(310, 130, 110, 20);

        jLabel18.setText("VSpeed:");
        jPanel2.add(jLabel18);
        jLabel18.setBounds(250, 160, 50, 14);

        jPanel2.add(vspeed);
        vspeed.setBounds(310, 160, 110, 20);

        jLabel19.setText("GSpeed:");
        jPanel2.add(jLabel19);
        jLabel19.setBounds(250, 190, 50, 14);

        jPanel2.add(gspeed);
        gspeed.setBounds(310, 190, 110, 20);

        jLabel20.setText("AOA:");
        jPanel2.add(jLabel20);
        jLabel20.setBounds(250, 220, 50, 14);

        jPanel2.add(aoa);
        aoa.setBounds(310, 220, 110, 20);

        jLabel21.setText("Slip:");
        jPanel2.add(jLabel21);
        jLabel21.setBounds(250, 250, 50, 14);

        jPanel2.add(slip);
        slip.setBounds(310, 250, 110, 20);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, 436, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, 395, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox aileron;
    private javax.swing.JComboBox airspeed;
    private javax.swing.JComboBox altitude;
    private javax.swing.JComboBox aoa;
    private javax.swing.JComboBox baroalt;
    private javax.swing.JTextField dstAddr;
    private javax.swing.JTextField dstPort;
    private javax.swing.JComboBox elevator;
    private javax.swing.JTextField filterAlpha;
    private javax.swing.JCheckBox filterEnable;
    private javax.swing.JComboBox flaps;
    private javax.swing.JComboBox gspeed;
    private javax.swing.JComboBox heading;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JComboBox latitude;
    private javax.swing.JComboBox longitude;
    private javax.swing.JTextField offset;
    private javax.swing.JCheckBox offsetEnable;
    private javax.swing.JComboBox pitch;
    private javax.swing.JComboBox roll;
    private javax.swing.JComboBox rpm;
    private javax.swing.JComboBox rudder;
    private javax.swing.JTextField selfAddr;
    private javax.swing.JComboBox slip;
    private javax.swing.JComboBox throttle;
    private javax.swing.JComboBox vspeed;
    // End of variables declaration//GEN-END:variables

	private final String gr = AppConfig.FLIGHTGEAR;
}
